home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Apple Script / OSAX / Finder Scripting Toolkit v1.0 / fwin coercion osax / list2fwin.c < prev    next >
Text File  |  1993-07-20  |  2KB  |  90 lines

  1. /*
  2.  
  3.         F W I N   C O E R C I O N   O S A X
  4.         
  5.         Version 1.0
  6.         Freeware by Daniel Ranson
  7.         
  8.         This osax performs coercions to the FinderWindow (fwin) record
  9.         type used by Finder events.
  10.         
  11.         There are actually three osax. This one converts a special type
  12.         of list that can be used to refer to folder, get info or sharing
  13.         windows. The format is :
  14.             { kind, alias }
  15.         Alias is an alias to the object the window is associated with.
  16.         Kind is an integer indicating the kind of window. The possible
  17.         values are :
  18.              0 : folder window
  19.             11 : get info window
  20.             13 : sharing window
  21.  
  22. */
  23.  
  24. #include <Types.h>
  25. #include <Memory.h>
  26. #include <Aliases.h>
  27. #include <AppleEvents.h>
  28. #include <AERegistry.h>
  29.  
  30. struct FinderWindow{
  31.     long        windowType;
  32.     DescType    aliasType;
  33.     long        aliasLength;
  34.     AliasRecord    alias;
  35. };
  36.  
  37. typedef struct FinderWindow FinderWindow;
  38.  
  39. /* This osax takes a descriptor in, while the other two take a buffer */
  40. pascal OSErr LIST2FWIN(    AEDesc         fromDesc,
  41.                         DescType    toType,
  42.                         long        refCon,
  43.                         AEDesc        *result)
  44. {
  45. #pragma unused(toType, refCon)
  46.  
  47.     FinderWindow    **hFwin;
  48.     Size            sizH;
  49.     long            val;
  50.     AEKeyword        aKey;
  51.     DescType        aType;
  52.     Size            aSize;
  53.     OSErr            err;
  54.     
  55.     /* Get kind */
  56.     err = AEGetNthPtr(&fromDesc, 1, typeLongInteger, &aKey, &aType,
  57.                         &val, 4, &aSize);
  58.     if ((err != noErr) || ((val != 0) && (val != 11) && (val != 13)))
  59.         return errAECoercionFail;
  60.     
  61.     /* Get alias size */
  62.     err = AESizeOfNthItem(&fromDesc, 2, &aType, &aSize);
  63.     if (err != noErr) return errAECoercionFail;
  64.     
  65.     /* Allocate the structure */
  66.     sizH = aSize + sizeof(FinderWindow) - sizeof(AliasRecord);
  67.     hFwin = (FinderWindow**)NewHandle(sizH);
  68.     if (hFwin == 0) return errAECoercionFail;
  69.     
  70.     /* Fill in fields */
  71.     (**hFwin).windowType = val;
  72.     (**hFwin).aliasType = typeAlias;
  73.     (**hFwin).aliasLength = aSize;
  74.     
  75.     /* Create the descriptor */
  76.     MoveHHi((Handle)hFwin);
  77.     HLock((Handle)hFwin);
  78.     err = AEGetNthPtr(&fromDesc, 2, typeAlias, &aKey, &aType,
  79.                         &((**hFwin).alias), aSize, &aSize);
  80.     if (err != noErr){
  81.         DisposeHandle((Handle)hFwin);
  82.         return errAECoercionFail;
  83.     }
  84.     err = AECreateDesc(typeFinderWindow, (Ptr)(*hFwin), sizH, result);
  85.     
  86.     /* Clean up */
  87.     DisposeHandle((Handle)hFwin);
  88.     return err;
  89. }
  90.